package code.rocky.singleThreadExecution;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户任务
 */
public class UserThread extends Thread {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * final 与 创建线程安全的实例
     */
    private final SafeGate safeGate;

    private final User user;

    public UserThread(SafeGate safeGate, User user) {
        this.safeGate = safeGate;
        this.user = user;
    }

    @Override
    public void run() {
        log.info("线程: {} 姓名:{} 经过安全门",Thread.currentThread().getName(),user.getName());
        while (true) {
            safeGate.pass(user);
        }
    }
}
